﻿using System;
using System.Linq.Expressions;

namespace MyBasicLib.Data.ORMLiteNew.Translation
{
    public class UpdateActionParser : ExpressionParser
    {
        //protected override IEnumerable<MemberBinding> VisitBindingList(ReadOnlyCollection<MemberBinding> original) {
        //    int n = original.Count;
        //    for (int i = 0; i < n; i++) {
        //        VisitBinding(original[i]);
        //    }
        //    if (original.Count > 0)
        //        Sb.Length--;
        //    return original;
        //}

        protected override MemberAssignment VisitMemberAssignment(MemberAssignment assignment)
        {
            string col = assignment.Member.Name;
            Sb.AppendFormat("[t0].[{0}]", col);
            Sb.Append(" = ");
            Visit(assignment.Expression);
            Sb.Append(",");
            return assignment;
        }

        protected override Expression VisitUnary(UnaryExpression u)
        {
            switch (u.NodeType)
            {
                case ExpressionType.Not:
                    Sb.Append("~");
                    break;
                case ExpressionType.Quote:
                    break;
                default:
                    throw new NotSupportedException();
            }
            Visit(u.Operand);
            return u;
        }
    }
}